﻿@page "/en/5.8/modules/kp-telegram"
@{
    Layout = "_ArticleLayout";
    ViewBag.Title = "Telegram Driver";
}

<nav class="doc-toc">
    <div class="h6">On this page</div>
    <hr>
    <ul>
        <li><a href="#overview">Overview</a></li>
        <li><a href="#installation">Installation</a></li>
        <li>
            <a href="#configuring">Configuring</a>
            <ul>
                <li><a href="#creating-bot">Creating Telegram Bot</a></li>
                <li><a href="#driver-settings">Driver Settings</a></li>
                <li><a href="#manage-subscriptions">Manage Subscriptions</a></li>
            </ul>
        </li>
        <li><a href="#sending-messages">Sending Messages</a></li>
    </ul>
</nav>

<div class="doc-content">
    <h1>Telegram Driver</h1>
    <h2 id="overview">Overview</h2>
    <p>Telegram Driver is designed to send notifications using the popular Telegram messenger. The advantages of using Telegram is quickness of receiving notifications, no fee for the service and easy management of notification groups.</p>

    <h2 id="installation">Installation</h2>
    <p>Telegram Driver is installed in accordance with <a href="../installation-and-run/module-installation.html#drivers">the general sequence of installing Communicator drivers</a>. The driver library file is KpTelegram.dll.</p>

    <h2 id="configuring">Configuring</h2>
    <h3 id="creating-bot">Creating Telegram Bot</h3>
    <p>First you need to create a Telegram bot. To do this:</p>
    <ol>
        <li>Install the application and register <a href="https://telegram.org/" target="_blank">Telegram</a>.</li>
        <li>
            Add the bot named <a href="https://telegram.me/botfather" target="_blank">BotFather</a> to the contact list.
            <figure class="figure text-start">
                <img src="kp-telegram-files/bot_father.png" class="figure-img img-fluid border" alt="Telegram BotFather" />
            </figure>
        </li>
        <li>In the dialog with BotFather, run the command <em>/newbot</em> and follow the instructions from BotFather.</li>
        <li>
            Click the menu icon and create a new group to receive notifications.
            <figure class="figure text-start">
                <img src="kp-telegram-files/new_group.png" class="figure-img img-fluid border" alt="New Telegram group" />
            </figure>
        </li>
        <li>Add the bot you created to the new group.</li>
        <li>Add contacts to the new group. These contacts will receive notifications.</li>
    </ol>

    <h3 id="driver-settings">Driver Settings</h3>
    <p>Configuring of notifications is performed using the Administrator application as part of a project. The configuring steps are:</p>
    <ol>
        <li>Open the <em>Device types</em> table and check that the device type &quot;224 Telegram&quot; exists. If the specified record is missing, enter it manually.</li>
        <li>Create a separate communication line and a single device of the Telegram type that belongs to this communication line. Use wizards that are opened by the <img src="../common-images/add_line.png" /> and <img src="../common-images/add_device.png" /> buttons.</li>
        <li>
            In the Communicator settings open the device properties, enter the bot token obtained when creating the bot, and generate a bot password that is needed to manage subscriptions.
            <figure class="figure text-start">
                <img src="kp-telegram-files/kp_telegram_config_en.png" class="figure-img img-fluid" alt="Telegram Driver configuration" />
            </figure>
        </li>
        <li>Save the driver configuration.</li>
        <li>Upload the project to the server by the <img src="../common-images/upload.png" /> button.</li>
        <li>
            Go to the <em>Registration</em> page and register the driver using the hyperlinks on the form.
            <figure class="figure text-start">
                <img src="kp-telegram-files/kp_telegram_reg_en.png" class="figure-img img-fluid" alt="Telegram Driver registration" />
            </figure>
        </li>
        <li>Save the changes again and upload the project to the server.</li>
    </ol>

    <h3 id="manage-subscriptions">Manage Subscriptions</h3>
    <p>If the settings are correct, your bot will respond to messenger commands, for example, the <em>/help</em> command. It is necessary to specify the subscriptions (chats) in the driver settings.</p>
    <figure class="figure">
        <img src="kp-telegram-files/group_chat_en.png" class="figure-img img-fluid border" alt="Telegram notification group" />
    </figure>
    <p>To get the ID and the name of the subscription, send the <em>/info</em> command using the messenger. Then add the received values using the device configuration form.</p>
    <p>Obsolete method: to add or remove subscriptions, use the <em>/start</em> and <em>/stop</em> commands with the previously generated password. However, by default, subscription changes are blocked. To unlock it, send a standard command number 2 with a value of 1 by Communicator. Then you can add or remove subscriptions.</p>

    <h2 id="sending-messages">Sending Messages</h2>
    <p>To send a message from Rapid SCADA to a Telegram group, you need send a binary command number 1 containing the group name (or identifier) and the message text. For example:<br />RapidScadaDemo; Test message.</p>
    <figure class="figure">
        <img src="kp-telegram-files/send_cmd_en.png" class="figure-img img-fluid" alt="Sending Telegram message" />
    </figure>
    <p>Automatic sending of notifications in case of specific conditions and events are performed by <a href="mod-auto-control">Automatic Control Module</a>.</p>
</div>
